﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_PRODUCT.Product.database;

namespace ERP_RORZE_PRODUCT.Product.PartData
{
    public partial class frm_MaterialEdit : DevExpress.XtraEditors.XtraForm
    {
        ClsPartDataDAO clsPartdataDAO = new ClsPartDataDAO();
        DataTable dt;
        ClsMaterialTable obj = new ClsMaterialTable();
        public event EventHandler Reload;

        private LogUtils log;
        public string MaterialID;
        public string Density;
        public string UnitPrice;
        public string Type;

        public frm_MaterialEdit()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frm_MaterialEdit_Load(object sender, EventArgs e)
        {
            txtDensity.Text = Density;
            txtMaterialID.Text = MaterialID;
            txtType.Text = Type;
            txtUnitPrice.Text = UnitPrice;
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtDensity.Text == "")
            {
                MessageBox.Show(" chưa nhập Density");
            }
            else
            {
                try
                {
                    obj.Density = float.Parse(txtDensity.Text);
                    obj.MaterialID = txtMaterialID.Text;
                    obj.Type = txtType.Text;
                    obj.UnitPrice = decimal.Parse(txtUnitPrice.Text);
                    clsPartdataDAO.UpdateMaterial(txtMaterialID.Text, txtDensity.Text, txtType.Text, txtUnitPrice.Text);

                    //write Log
                    log.Table = LogConstant.Table.Product.MaterialList;
                    log.Task = LogConstant.Task.Update;
                    log.Description = "MaterialID: " + obj.MaterialID;
                    log.WriteLog();

                    MessageBox.Show("Đã nhập xong");
                    //Reload(sender, e);
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Density là kiểu số thực và UnitPrice là kiểu money");
                }
            }
        }
        protected override bool ProcessKeyPreview(ref Message m)
        {
            if (m.Msg == 0x0100 && (int)m.WParam == 13)
            {
                this.ProcessTabKey(true);
            }
            return base.ProcessKeyPreview(ref m);
        }
    }
}